package com.cjm.algorithm.leetcode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Intersection349 {
    public static int[] intersection(int[] nums1, int[] nums2) {
        if (nums1.length < 1 || nums2.length < 1) {
            return new int[0];
        }
        Set<Integer> set = new HashSet<>();
        for (int i = 0;i<nums1.length;i++) {
            set.add(nums1[i]);
        }

        Set<Integer> resSet = new HashSet<>();
        for (int i = 0; i < nums2.length; i++) {
            if (set.contains(nums2[i])) {
                resSet.add(nums2[i]);
            }
        }
        int[] res = new int[resSet.size()];
        int index = 0;
        for (Integer integer : resSet) {
            res[index] = integer;
            index++;
        }

        return res;
    }

    public static void main(String[] args) {
        int[] intersection = intersection(new int[]{1, 2, 2, 1}, new int[]{2, 2});
        int[] intersection1 = intersection(new int[]{4, 9, 5}, new int[]{9, 4, 9, 8, 4});
        System.err.println("IK");
    }
}
